package legumes.shared.domain;

import java.io.Serializable;

import javax.persistence.Id;

public class PostalAdress implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Id private long id;
	private String civility;
	private String lastName;
	private String firstName;
	
	private String companyName;
	private String flat;
	private String building;
	private String street;
	private String placeCalled;
	private String zipCode;
	private String town;
	private String country;
	private String phone1;
	private String phone2;
	//Ex : Digicode; Give to concierge
	private String adressPrecision;
	
	public PostalAdress() {
		super();
		civility = CivilityEnum.Sir.name();
	}

	@Override
	public String toString() {
		String space = " ";
		String lineSeparator = "\n";
		return getCivility() + space + getLastName() + space + getFirstName() + lineSeparator + 
			getCompanyName() +
				getFlat() + space + getBuilding() + space + lineSeparator +
				getPlaceCalled() + lineSeparator +
				getStreet() + space + getZipCode() + space + getTown() + lineSeparator + 
				getCountry() + lineSeparator + 
				getPhone1() + space + getPhone2() + lineSeparator + 
				getAdressPrecision();
	}
	
	public String toStringAdressPostal() {
		return  toStringAdressPostal(" ", " "); 
	}
	
	public String toStringHTMLAdressPostal() {
		return toStringAdressPostal("&nbsp;", "<BR/>"); 
	}
	
	private String toStringAdressPostal(String space, String lineSeparator) {
		StringBuffer sb = new StringBuffer();
		if(getPlaceCalled()!=null){
			sb.append(getPlaceCalled() + lineSeparator);
		}
		
		if(getStreet()!=null){
			sb.append(getStreet() + lineSeparator);
		}
		
		if(getZipCode()!=null){
			sb.append(getZipCode() + space);
		}
		
		if(getTown()!=null){
			sb.append(getTown());
		}
		sb.append(lineSeparator);
		if(getCountry()!=null){
			sb.append(getCountry());
		}
		return  sb.toString(); 
	}
	
	public String getCivility() {
		return civility;
	}

	public void setCivility(String civility) {
		this.civility = civility;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public String getFlat() {
		return flat;
	}

	public void setFlat(String flat) {
		this.flat = flat;
	}

	public String getBuilding() {
		return building;
	}

	public void setBuilding(String building) {
		this.building = building;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getPlaceCalled() {
		return placeCalled;
	}

	public void setPlaceCalled(String placeCalled) {
		this.placeCalled = placeCalled;
	}

	public String getZipCode() {
		return zipCode;
	}

	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}

	public String getTown() {
		return town;
	}

	public void setTown(String town) {
		this.town = town;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getPhone1() {
		return phone1;
	}

	public void setPhone1(String phone1) {
		this.phone1 = phone1;
	}

	public String getPhone2() {
		return phone2;
	}

	public void setPhone2(String phone2) {
		this.phone2 = phone2;
	}

	public String getAdressPrecision() {
		return adressPrecision;
	}

	public void setAdressPrecision(String adressPrecision) {
		this.adressPrecision = adressPrecision;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

}
